#include "IntArray.h"

IntArray::IntArray(int len)
{
	m_len = len;
}
bool IntArray::construct(int len)
{
	bool ret = true;
	m_point = new int[len];
	if (!m_point)
	{
		delete m_point;
		m_point = 0;
		ret = false;
	}
	return ret;
}

IntArray* IntArray::NewInstance(int len)
{
	IntArray* ret = new IntArray(len);
	if (!(ret && ret->construct(len)))
	{
		delete ret;
		ret = 0;
	}
	return ret;
}

IntArray& IntArray::operator = (const IntArray& obj)
{
	if (this != &obj)
	{
		int *p = new int[obj.length()];
		if (p)
		{
			for (int i = 0; i < obj.length(); i++)
			{
				p[i] = obj.m_point[i];
			}
			m_len = obj.m_len;
			delete[] m_point;
			m_point = new int[m_len];
			if (m_point)
			{
				m_point = p;
			}
			else
			{
				delete[] m_point;
				m_point = 0;
			}
		}
		else
		{
			delete[] p;
			p = 0;
		}
	}

	return *this;
}
	
IntArray& IntArray::self()
{
	return *this;
}

int IntArray::length() const
{
	return m_len;
}
	
int& IntArray::operator [] (int n)
{
	return m_point[n];
}